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,0,0,1,1,1,0,1,0,0,0,0,1,0,1,0,0,0,0,1,0,0,0,1,0,1,0,0,1,0,0,1,1,0,0,0,1,0,
1,1,0,1,0,0,0,0,0,0,0,1,0,0,1,0,0,1,1,0,0,1,0,0,0,1,0,0,1,1,0,0,1,0,0,0,0,1,0,1,
1,0,0,1,1,0,0,0,1,0,1,0,0,0,1,0,0,0,0,1,0,0,0,0,0,1,0,1,1,1,1,1,1,1,1,1,1,1,0,0,
1,0,0,1,0,1,1,0,1,0,1,0,1,1,0,0,0,0,1,0,0,0,0,0,0,0,1,1,0,0,0,1,1,0,1,1,0,0,0,0,
0,0,1,1,0,0,0,1,0,0,0,1,1,0,0,0,0,1,0,1,1,1,1,0,1,0,0,0,1,0,1,1,1,0,1,1,0,0,0,1,
	};
typedef struct wsad{
    int x;int y;
}xy;
int bfs(int n,int m){
	int dx[] = { -1, 0, 1, 0 };
	int dy[] = { 0, 1, 0, -1 };
	int flag2=1,ll=0,rr=0;
	int i,x,y;
    xy line[1200]={0};//行迹
    map[0][0]=1;
	while (ll<=rr){
		xy old=line[ll++];
		for (i = 0; i < 4; i++){
            x = old.x + dx[i];
			y = old.y + dy[i];
			if (x>0 && x <30 && y > 0 && y <40 && map[x][y] == 0){
                map[x][y]=map[old.x][old.y]+1;//记录步数
                line[++rr]=x;line[rr]=y;//记录步
            }
				
			
		}
	}return map[29][39];
}


int main(){
	bfs();
	return 0;
}
